package com.example.flshtarvel.service;

import com.example.flshtarvel.entity.Tag;
import com.example.flshtarvel.mapper.TagMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import java.sql.ResultSet;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service
public class TagService {
    @Autowired(required = false)
    TagMapper tagMapper;

    public Tag selectTagById(String tagId){
        return tagMapper.selectTagById(tagId);
    }

    public List<Tag> selectTagByName(String tagName){
        String likeSql = "%"+tagName+"%";
        return tagMapper.selectTagByName(likeSql);
    }

    public List<Tag> selectAllTagByTagTypeId(String tagTypeId,int page, int size){
        //计算偏移量
        int offset = (page-1)*size;
        return tagMapper.selectAllTagByTagTypeId(tagTypeId,offset,size);
    }

    public int selectTagCountByTagTypeId(String tagTypeId){
        return tagMapper.selectTagCountByTagTypeId(tagTypeId);
    }

    public int insertTag(Tag tag){
        //检查是否已有该数据
        Tag tagResult = tagMapper.selectTag(tag.getTagName());
        if(tagResult==null){
            tag.setTagId(UUID.randomUUID().toString());
            return tagMapper.insertTag(tag);
        }else{
            return 0;
        }

    }

    public int deleteTagById(String tagId){
        return tagMapper.deleteTagById(tagId);
    }
    //只搜索地点标签  通过标签名
    public List<Tag> selectAddressTagByName(String tagName){
        String likeSql = '%'+tagName+'%';
        List<Tag> tagList = tagMapper.selectAddressTagByName(likeSql);
        return tagList;
    }

    //查询所有标签
    public List<Tag> selectAllTag(){
        List<Tag> tagList = tagMapper.selectAllTag();
        return tagList;
    }



}
